//
//  LPJoinPersonListTableViewCell.m
//  ShangHaiHuDongApp
//
//  Created by 刘应平 on 2017/7/2.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "LPJoinPersonListTableViewCell.h"

@interface LPJoinPersonListTableViewCell ()
/**  headerImeView  */
@property (strong, nonatomic) UIImageView  *headerImagView;
/**  namE  */
@property (strong, nonatomic) UILabel  *nameLabel;
/**  状态  */
@property (strong, nonatomic) UILabel  *statusLabel;
/**  代签  */
@property (strong, nonatomic) UILabel  *allograph;


@end
@implementation LPJoinPersonListTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

/**  60  */
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self addSubview:self.headerImagView];
        [self addSubview:self.nameLabel];
        [self addSubview:self.statusLabel];
        [self addSubview:self.allograph];
        
        
        self.headerImagView.sd_layout
        .topSpaceToView(self, 10 * [UIScreen zj_screenHScale])
        .leftSpaceToView(self, 20 * [UIScreen zj_screenWScale])
        .heightIs(40 * [UIScreen zj_screenHScale])
        .widthIs(40 * [UIScreen zj_screenHScale]);
        
        
        
        self.nameLabel.sd_layout
        .topSpaceToView(self, 20 * [UIScreen zj_screenHScale])
        .leftSpaceToView(self.headerImagView, 15 * [UIScreen zj_screenWScale])
        .heightIs(20 * [UIScreen zj_screenHScale])
        .widthIs(150 * [UIScreen zj_screenHScale]);
        
        
        self.statusLabel.sd_layout
        .topSpaceToView(self, 20 * [UIScreen zj_screenHScale])
        .rightSpaceToView(self, 20 * [UIScreen zj_screenWScale])
        .heightIs(20 * [UIScreen zj_screenHScale])
        .widthIs(80);
        
        self.allograph.sd_layout
        .topSpaceToView(self, 17 * [UIScreen zj_screenHScale])
        .rightSpaceToView(self.statusLabel, 10 * [UIScreen zj_screenWScale])
        .heightIs(26 * [UIScreen zj_screenHScale])
        .widthIs(45 * [UIScreen zj_screenWScale]);
        
       
        
        
        
        UIView *under = [UIView new];
        under.backgroundColor = [UIColor themeGrayColor];
        [self addSubview:under];
        under.sd_layout.leftEqualToView(self).bottomEqualToView(self).widthIs([UIScreen zj_screenWith]).heightIs(1);
    }
    return self;
}

- (void)tapLabel{
    if (self.delegate) {
        if ([self.allograph.text isEqualToString:@"催报"]) {
            [self.delegate LPJoinPersonListTableViewAllograph_index:self.row isApply:YES];
        }else{
            [self.delegate LPJoinPersonListTableViewAllograph_index:self.row isApply:NO];
        }
    }
}


- (void)setModel:(LPJoinPersonListModel *)model{
    _model = model;
    self.nameLabel.text = model.USER_NAME;
    [self.headerImagView sd_setImageWithURL:CREATEURL(model.PHOTO_THUMBURL) placeholderImage:PlaceholderHeaderImage];
    
    if ([model.ENROLL isEqualToString:@"1"]) {
        if ([model.SIGN isEqualToString:@"1"]) {
            self.statusLabel.text = @"已签到";
            self.allograph.hidden = YES;
        }else{
            if ([model.LEAVE isEqualToString:@"1"]) {
                self.allograph.hidden = YES;
                if ([model.LEAVE_STATE integerValue] == 0) {
                    self.statusLabel.text = @"待审核";
                }else if ([model.LEAVE_STATE integerValue] == 1){
                    self.statusLabel.text = @"审核通过";
                }else if ([model.LEAVE_STATE integerValue] == 2){
                
                    self.statusLabel.text = @"审核不通过";
                }
            }else{
                self.statusLabel.text = @"已报名";
                self.allograph.text = @"代签";
                self.allograph.hidden = NO;
            }
            
        }
    
    }else{
        self.allograph.hidden = NO;
        self.statusLabel.text = @"未报名";
        self.allograph.text = @"催报";

    }
    
    CGFloat width = [CalculateLabelHeight CalculateLabelWidthWithString:self.statusLabel.text font:15 height:20 * [UIScreen zj_screenHScale]].width;
    self.statusLabel.sd_layout.widthIs(width);
    [self.statusLabel updateLayout];
    
    if ([model.ACCOUNTID isEqualToString:ZJUSERINFORMODEL.ORG_ACCOUNT.ID]) {
        self.allograph.hidden = YES;
    }
    
}


- (UIImageView *)headerImagView{
    if (!_headerImagView) {
        _headerImagView = [UIImageView new];
        _headerImagView.contentMode = UIViewContentModeScaleToFill;

    }
    return _headerImagView;
}



- (UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor textBlackColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = LYPFONT(16);
            label;
        });
    }
    return _nameLabel;
}


- (UILabel *)statusLabel{
    if (!_statusLabel) {
        _statusLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentRight;
            label.textColor = [UIColor zj_colorWithHexString:@"f24141"];
            label.backgroundColor = [UIColor clearColor];
            label.font = LYPFONT(15);
            label;
        });
    }
    return _statusLabel;
}



- (UILabel *)allograph{
    if (!_allograph) {
        _allograph = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentCenter;
            label.textColor = [UIColor whiteColor];
            label.font = LYPFONT(15);
            label.layer.cornerRadius = 6;
            label.layer.masksToBounds = YES;
            label.backgroundColor = [UIColor themeColor];
            label.userInteractionEnabled = YES;
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapLabel)];
            [label addGestureRecognizer:tap];
            label;
        });
    }
    return _allograph;
}

@end
